import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xin_he/page/mine/xin_he_bank_management/xin_he_bank_list_sheet/xin_he_bank_code_entity.dart';
import 'package:xin_he/utils/xh_styles.dart';

import '../../../../utils/xin_he_image.dart';
import 'xin_he_bank_list_sheet_logic.dart';

class XinHeBankListSheetPage extends StatelessWidget {
  XinHeBankListSheetPage({Key? key}) : super(key: key);



  @override
  Widget build(BuildContext context) {
    final logic = Get.put(XinHeBankListSheetLogic());
    final state = Get.find<XinHeBankListSheetLogic>().state;

    return Obx(() => Container(
      width: Get.width,
      height: 44*9+Get.mediaQuery.padding.bottom+40+60,
      color: Colors.transparent,
      child: Column(children: [
        
        Container(
          height: 60,
          color: Colors.white,
          padding: EdgeInsets.symmetric(horizontal: 15),
          child: Row(
            children: [
              GestureDetector(
                onTap:(){
                  Get.back();
                },
                  child: Text('取消')),
              Spacer(),
              const Text('请选择银行',style: TextStyle(fontSize: 18,fontWeight: FontWeight.bold),),
              Spacer(),
              GestureDetector(
                  onTap: (){
                    XinHeBankCodeEntity model = logic.dataList[logic.selectedIndex.value];
                    Get.back(result: model);

                  },
                  child: Text('确定',style: TextStyle(color: XinHeStyle.mainGreenColor),))
            ],
          ),
        ),
        Expanded(child: Container(
          width: Get.width,
          padding: const EdgeInsets.symmetric(horizontal: 37.5),
          color: Colors.white,
          child: ListView.builder(
              itemCount: logic.dataList.length,
              itemBuilder: (ctx, index){
                XinHeBankCodeEntity model = logic.dataList[index];

                return GestureDetector(
                  onTap: () {
                    logic.selectedIndex.value = index;
                    List tmp = [...logic.dataList.value];
                    for(int i= 0; i< tmp.length; i++ ){
                      XinHeBankCodeEntity obj = tmp[i];

                      if(i != index) {
                        obj.selected = false;
                      }else {
                        obj.selected = true;
                      }
                    }
                    logic.dataList.value = tmp;
                    // Get.back(result: model);
                  },
                  child: Container(
                      alignment: Alignment.center,
                      height: 44,
                      color: model.selected?Colors.blueGrey:Colors.white,
                      child: Text(model?.name??'',style: TextStyle(color: model.selected? XinHeStyle.mainGreenColor: Colors.black ),)
                  ),
                );
              }),
        ))
      ],),
    ));
  }
}
